package com.lujieni.springbootsecurity.config;

import com.lujieni.springbootsecurity.dao.UserMapper;
import com.lujieni.springbootsecurity.service.UserDetailServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 不用的配置,我们不走AuthenticationManager进行用户的认证
 */
@RequiredArgsConstructor
public class UnUseWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

    private final UserMapper userMapper;

    // 使用加密方式将原密码进行encode,比对数据库里的密码
    @Bean
    PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    // 1.AuthenticationManager使用我们自己的UserDetailServiceImpl
    @Override
    public void configure(AuthenticationManagerBuilder builder) throws Exception {
        builder.userDetailsService(new UserDetailServiceImpl(userMapper));
    }

    // 2.暴露AuthenticationManager对象到容器中
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }







}
